package com.longk.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.longk.dao.ArticleMapper;
import com.longk.dao.UserMapper;
import com.longk.moduel.Article;
import com.longk.moduel.User;

@RestController
public class IndexController {
	@Autowired
	UserMapper usermapper;
	@Autowired
	ArticleMapper articleMapper;
@RequestMapping("/test1")
	public String test() {
		
	User user=usermapper.getUserById("1");
    
	
	return user.getUsername();
	}

@RequestMapping("/index")
public ModelAndView  index(HttpServletRequest request) {
	
	List<Article> list=articleMapper.selectArticle(0, 5);
	List<Article> newlist=articleMapper.selectArticle(0, 5);
	ModelAndView view = new ModelAndView("/index.btl");
	request.setAttribute("acticleList", list);
	request.setAttribute("newActicleList", newlist);
	return view;
}



@RequestMapping("/article")
public ModelAndView  article(HttpServletRequest request,int id) {
	articleMapper.countArticleHits(id);
 Article art=articleMapper.selectArticleById(id);
 
	ModelAndView view = new ModelAndView("/article.btl");
	request.setAttribute("acticle", art);
	return view;
}

}